import requsest from '@/utils/request'
import { Message } from 'element-ui';
export const savapage=(article)=>{
    return requsest({
        method:"POST",
        url:"http://localhost:8080/article/savePage",
        data:article
    }).then(
          response=>{
              if(response.data.success){
                //    sessionStorage.setItem('token',response.data.data.token)
                //    return true;
                Message.success("已成功保存到草稿箱")
                 
              }
          },
          error=>{
            Message.error("保存失败")
            console.log("请求失败"+error.message);
          }

        )
}
export const uploadArticle=(article)=>{
  return requsest({
      method:"POST",
      url:"http://localhost:8080/article/uploadArticle",
      data:article
  }).then(
        response=>{
            if(response.data.success){
              //    sessionStorage.setItem('token',response.data.data.token)
              Message.success("已成功发布")
              return true;
             
               
            }
        },
        error=>{
          Message.error("发布失败")
          console.log("发布失败"+error.message);
        }

      )
}
export const getAllArticles=()=>{
  return requsest({
      method:"GET",
      url:"http://localhost:8080/article/getAllArticles",
  }).then(
        response=>{
            if(response.data.success){
              return response.data.data;
            }
        },
        error=>{
          Message.error("获取失败")
          console.log("获取失败"+error.message);
        }

      )
}
export const getHotpotArticles=()=>{
    return requsest({
        method:"GET",
        url:"http://localhost:8080/article/getHotpotArticles",
    }).then(
        response=>{
            if(response.data.success){
                return response.data.data;
            }
        },
        error=>{
            Message.error("获取失败")
            console.log("获取失败"+error.message);
        }

    )
}
export const deleteArticle=(articleId)=>{
  return requsest({
      method:"DELETE",
      url:"http://localhost:8080/article/deleteArticleById",
      data:articleId
  }).then(
        response=>{
            if(response.data.success){
             

              Message.success("删除成功")
               setTimeout(()=>{
            location.reload();
          },500)
               
            }
        },
        error=>{
          Message.error("删除失败")
          console.log("删除失败"+error.message);
        }

      )
}
export const getArticleById=(articleId)=>{
  return requsest({
      method:"GET",
      url:`http://localhost:8080/article/getArticleById/${articleId}`,
      // params:articleId
  }).then(
       
        response=>{       
          if(response.data.success){
            return response.data.data;
          }
              
        },
        error=>{
          Message.error("获取失败")
          console.log("获取失败"+error.message);
        }

      )
}
export const getArticleListBySearchContent=(searchContent)=>{
    return requsest({
        method:"GET",
        url:`http://localhost:8080/article/getArticleListBySearchContent/${searchContent}`,

    }).then(

        response=>{
            if(response.data.success){
                return response.data.data;
            }

        },
        error=>{
            Message.error("获取失败")
            console.log("获取失败"+error.message);
        }

    )
}
export const countUserReleaseArticle=(userId)=>{
    return requsest({
        method:"Get",
        url:`http://localhost:8080/article/countUserReleaseArticle/${userId}`,
    }).then(
        response=>{
            if(response.data.success){
                return response.data.data;

            }
        },
        error=>{
            console.log("请求失败"+error.message);
        }

    )
}
export const getFollowArticles=()=>{
    return requsest({
        method:"Get",
        url:`http://localhost:8080/article/getFollowArticles/`,
    }).then(
        response=>{
            if(response.data.success){
                return response.data.data;

            }
        },
        error=>{
            console.log("请求失败"+error.message);
        }

    )
}